package net.oschina.bilbodai.common.beanutil.bean.creator;

import net.oschina.bilbodai.common.beanutil.bean.core.PropertyDumpInfo;
import net.oschina.bilbodai.common.beanutil.exception.PropertyDumpException;

import java.util.List;

/**
 * @author daimao  Date: 16/7/4 Time: 上午11:36
 * @version $Id$
 */
public class CodeApplierCreators {

    static void checkSorted(PropertyDumpInfo dumpInfo) {
        if (dumpInfo.isSorted()) {
            if (!List.class.isAssignableFrom(dumpInfo.getTargetField().getType())) {
                throw new PropertyDumpException("Sorted option only support List field Type, dumpInfo=" + dumpInfo);
            }
            if (dumpInfo.usingAttrPathQuery()) {
                if (!Comparable.class.isAssignableFrom(dumpInfo.getAttrPathQueryInfo().getPropertyType())) {
                    throw new PropertyDumpException("Attr Path Query Type need implement Comparable interface, dumpInfo=" + dumpInfo);
                }
            }
            if (!Comparable.class.isAssignableFrom(dumpInfo.getTargetComponentType())) {
                throw new PropertyDumpException("Target Component Type need implement Comparable interface, dumpInfo=" + dumpInfo);
            }
        }
    }
}